package com.wswy.wzcx.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import com.wswy.wzcx.R;
import com.wswy.wzcx.model.home.RPaths;
import com.wswy.wzcx.module.base.CBaseActivity;
import com.wswy.wzcx.module.base.CBaseFragment;
import com.wswy.wzcx.ui.card.MyLicenseFragment;
import com.wswy.wzcx.utils.UiUtils;
import org.jetbrains.annotations.Nullable;

public class ModuleHolderActivity extends CBaseActivity {

  private static final String EXTRA_TARGET_NAME = "extra.target_name";

  public static Intent getTargetIntent(Context context, String target) {
    Intent intent = new Intent(context, ModuleHolderActivity.class);
    intent.putExtra(EXTRA_TARGET_NAME, target);
    return intent;
  }

  protected CBaseFragment fragment = null;

  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_module_holder);

    String target = getIntent().getStringExtra(EXTRA_TARGET_NAME);
    if (!TextUtils.isEmpty(target)) {
      fragment = newFragment(target);
      if (fragment != null) {
        getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, fragment)
            .commitNow();
      } else {
        finish();
      }
    } else {
      finish();
    }

  }

  private CBaseFragment newFragment(String target) {
    CBaseFragment fragment = null;
    switch (target) {
      case RPaths.MY_LICENSE:
        fragment = new MyLicenseFragment();

        UiUtils.INSTANCE.setStatusBarLight(this,false);

        break;
    }

    return fragment;
  }


  @Override
  public void onBackPressed() {
    if (fragment != null && fragment.isAdded()) {
      if (!fragment.onBackPress()) {
        super.onBackPressed();
      }
    } else {
      super.onBackPressed();
    }
  }

  @Override
  protected boolean autoHackStatusBar() {
    return false;
  }
}
